package com.mifengs.mall.ui.msg;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengs.commonbase.util.StatusBarCompat;
import com.mifengs.commonbase.util.StatusBarUtils;
import com.mifengs.mall.R;
import com.mifengs.commonbase.base.BaseActivity;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import java.util.ArrayList;
import java.util.List;

public class MsgCenterActivity extends BaseActivity {

  private String [] str =new String[] {"我的消息","系统公告", "优惠促销"};
  private List<Fragment> mFragments = new ArrayList<>();
  private int type = 0;//0我的消息，1 系统公告 2 优惠促销

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_msg_center);
    StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.white));
    StatusBarUtils.StatusBarLightMode(this);
    initNavigationBar();
    type = getIntent().getIntExtra("type",0);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.smartTabLayout_msg);
    FragmentPagerItems pages = new FragmentPagerItems(this);
    for (String  titleResId : str) {
      pages.add(FragmentPagerItem.of(titleResId,MsgCenteFragment.class));
    }

    FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
        getSupportFragmentManager(), pages);

    viewPager.setAdapter(adapter);
//    viewPager.setCurrentItem(type-1);
    viewPager.setCurrentItem(type);
    viewPager.setOffscreenPageLimit(2);
    viewPagerTab.setViewPager(viewPager);

  }

  protected void initNavigationBar() {
    RelativeLayout llNavBar = (RelativeLayout) this.findViewById(R.id.navigation_bar);
    if (llNavBar != null) {
      LinearLayout llBack = (LinearLayout) this.findViewById(R.id.ll_back);
      llBack.setVisibility(View.VISIBLE);
      TextView titleText = (TextView) this.findViewById(R.id.tv_title);
      titleText.setVisibility(View.VISIBLE);
      titleText.setText("消息中心");
      llBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          finish();
        }
      });
    }
  }

}
